package demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;

public class Demo10 {
    public static void main(String[] args) {
        //ArrayList<String> list = new ArrayList<>();
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        list.add("Tom");
        list.add("Jerry");
        list.add("Andy");
        list.add("Lee");
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for (String name: list){
                    System.out.println(name);
                }
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                list.add(0, "Wang");
            }
        };
        t2.start();

    }
}
